<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Cache;
//use think\helper\Arr;
use think\Exception;

use app\common\services\FeedbackService;

/**
 * 意见反馈
 */
class Feedback extends Api
{
    
    protected $noNeedRight = '*';
    
    /**
     * 添加意见反馈
     */
    public function add(){
        
        $user = $this->auth->getUserinfo();
        
        $user_id = $user['id'];
        $key     = 'Feedback:'.$user_id;
        $this->checkRepeatKey($key);
        
        
        $data = $this->request->param('');
        if((isset($data['content']) && empty($data['content']))){
            return $this->error('参数错误');
        }

        $data['image']    = array_column($data['image']??[],'url');
        
        $data['uid']      = $user_id;
        $data['username'] = $user['username'];
        
        try {
            FeedbackService::add($data);
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
        return $this->success('success');
    }
}
